package org.example.handler;

import jdk.jshell.spi.ExecutionControl;
import lombok.extern.slf4j.Slf4j;
import org.example.util.JsonResult;
import org.example.util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther:Liu
 * @Testname:GlobalExceptionHandler
 * @Date:2025/8/5 15:03
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(UserSaveException.class)
    public JsonResult userSaveException(Throwable e) {
        return ResultTool.fail(500, e.getMessage());
    }

    @ExceptionHandler(UserUpdateException.class)
    public JsonResult userUpdateException(Throwable e) {
        return ResultTool.fail(502, e.getMessage());
    }

    @ExceptionHandler(BookSaveException.class)
    public JsonResult bookSaveException(Throwable e) {
        return ResultTool.fail(503, e.getMessage());
    }

    @ExceptionHandler(CategoryRemoveExveption.class)
    public JsonResult categoryRemoveExveption(Throwable e) {
        return ResultTool.fail(504, e.getMessage());
    }

    @ExceptionHandler(UserNotFoundException.class)
    public JsonResult userNotFoundException(Throwable e) {

        return ResultTool.fail(505, e.getMessage());
    }

    @ExceptionHandler(PasswordFailException.class)
    public JsonResult passwordFailException(Throwable e) {
        return ResultTool.fail(505, e.getMessage());
    }

    @ExceptionHandler(NameIsCreatedException.class)
    public JsonResult nameIsCreatedException(Throwable e) {
        return ResultTool.fail(505, e.getMessage());
    }

    @ExceptionHandler(PhoneIsCreatedException.class)
    public JsonResult phoneIsCreatedException(Throwable e) {
        return ResultTool.fail(505, e.getMessage());
    }
    @ExceptionHandler(EmailIsCreatedException.class)
    public JsonResult emailIsCreatedException(Throwable e) {
        return ResultTool.fail(505, e.getMessage());
    }
    @ExceptionHandler(UserNotLoginException.class)
    public JsonResult userNotLoginException(Throwable e) {
        return ResultTool.fail(505, e.getMessage());
    }

    @ExceptionHandler(OrderSaveException.class)
    public JsonResult orderSaveException(Throwable e) {
        return ResultTool.fail(506, e.getMessage());
    }
}
